package com.bdcom.nms.NmsCollect.task;

import java.io.IOException;
import java.util.List;

import org.opengoss.snmphibernate.api.ISnmpSession;
import org.opengoss.snmphibernate.api.ISnmpTarget;

import com.bdcom.nms.NmsCollect.pojo.ManagedObject;
import com.bdcom.nms.NmsCollect.thread.BdcomSwitchCollectThread;

/**
 * 博大交换机采集任务类，继承AbstractCollectTask类
 * 
 * @author Administrator
 *
 */
public class BdcomSwitchCollectTask extends AbstractCollectTask{
	
	
	private List<ManagedObject> L;
	
	private ManagedObject mo;
	
	private ISnmpSession session;
	
	private ISnmpTarget target;
	
	

	
	public BdcomSwitchCollectTask() {
		super();
		// TODO Auto-generated constructor stub
	}




	@Override
	public void collect() {
		// TODO Auto-generated method stub
		
		
		_log.info(this.getClass().getName()+":starting....CollectMethod");
		
		 L=findMoByType();
		
		for (int i=0;i<L.size();i++) {
			
			if(i%300==0){
				
				try {
					
					/**
					 * 如果执行的采集设备为300的倍数时，线程等待一下。
					 */
					Thread.sleep(30000);
					
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					_log.error("睡眠线程异常！"+e.getLocalizedMessage());
				}
				
			}
			  
				mo=L.get(i);
				
			/**
			 * 不同采集类的不同实现。
			 */
			target=targetFactory.newSnmpTarget(mo.getName());
			
			target.setCommunity(mo.getTopoobject().getCommunity());
			
			target.setWriteCommunity(mo.getTopoobject().getWritecommunity());
			
			/**
			 * 默认为v2
			 */
			target.setVersion(ISnmpTarget.V2C);
			
			/**
			 * 默认161
			 */
			target.setPort(161);
			
			try {
				session=sessionFactory.newSnmpSession(target);
				
				/**
				 * 线程池处理.
				 */
				collectthreadpoll.execute( new BdcomSwitchCollectThread(session, mo.getName()));
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				_log.error("创建"+mo.getName()+"snmpSession:IO异常！"+e.getLocalizedMessage());
				continue;
			}
			
		}
		
		_log.info(this.getClass().getName()+":terminating....CollectMethod");
		
	}

}
